﻿@using SelfMadeMillionaire.Web.Infrastructure.ViewModels.Newss
@using SelfMadeMillionaire.Web.Infrastructure
@model NewsListViewModel
@{
	ViewBag.Title = "News";
	Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
}

@using (Html.BeginForm("Index", "News", FormMethod.Get, new { @class = "form-horizontal" }))
{
	
	<fieldset class="border1">
		<legend class="border1">Search News</legend>
		<div class="row">
            @Html.HiddenFor(m => m.SortOrder)
			<div class="col-sm-3">
				<div class="form-group">
					@Html.LabelFor(model => model.StartDate, new { @class = "col-sm-6 control-label" })
					<div class="col-sm-6">
						@Html.TextBoxFor(m => m.StartDate, "{0:" + Constants.DATE_FORMAT + "}", new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.StartDate)
					</div>
				</div>
			</div>
			<div class="col-sm-3">
				<div class="form-group">
					@Html.LabelFor(model => model.EndDate, new { @class = "col-sm-6 control-label" })
					<div class="col-sm-6">
						@Html.TextBoxFor(m => m.EndDate, "{0:" + Constants.DATE_FORMAT + "}", new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.EndDate)
					</div>
				</div>
			</div>
			<div class="col-sm-6">
				<div class="form-group">
					@Html.LabelFor(model => model.SelectedProduct, new { @class = "col-sm-4 control-label" })
					<div class="col-sm-8">
						@Html.DropDownListFor(m => m.SelectedProduct, Model.ProductTypes, new { @class = "form-control" })
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					@Html.LabelFor(model => model.Title, new { @class = "col-sm-3 control-label" })
					<div class="col-sm-9">
						@Html.TextBoxFor(m => m.Title, new { @class = "form-control" })
					</div>
				</div>
			</div>
            <div class="col-sm-6">
				<div class="form-group">
                    @Html.LabelFor(model => model.MinAccessLevel, new { @class = "col-sm-4 control-label" })
			        <div class="col-sm-8">
				        @Html.DropDownListFor(m => m.MinAccessLevel, Model.AccessLevels, new { @class = "form-control" })
			        </div>
				</div>
			</div>
			
		</div>
        <div class="row">
            <div class="col-sm-10">
            </div>
            <div class="col-sm-2">
				<div class="pull-right">
					<button type="submit" id="find-news" class="btn btn-default">Find News</button>
				</div>
			</div>
        </div>
	</fieldset>
}

<div class="table_container">
	<div id="news-list">
		@Html.Partial("NewsList")
	</div>
	@Html.ActionLink("Add New", "Add", null, new { @class = "btn btn-default" })
</div>

<script type="text/javascript">
	$(function () {
	    RemoveTime("#@Html.IdFor(m=>m.StartDate)");
	    RemoveTime("#@Html.IdFor(m=>m.EndDate)");
	    $("#@Html.IdFor(m=>m.StartDate), #@Html.IdFor(m=>m.EndDate)").datepicker();

		$("#find-news").click(function (e) {
			e.preventDefault();
            
			GetList();
		});
	});

    function GetList() {
        $.get("@Url.Action("Index")",
				{
				    startDate: $("#@Html.IdFor(m => m.StartDate)").val(),
				    endDate: $("#@Html.IdFor(m => m.EndDate)").val(),
				    selectedProduct: $("#@Html.IdFor(m => m.SelectedProduct)").val(),
				    title: $("#@Html.IdFor(m => m.Title)").val(),
				    minAccessLevel: $("#@Html.IdFor(m => m.MinAccessLevel)").val(),
				    sort: $("#@Html.IdFor(m => m.SortOrder)").val(),
                    page: '@(Model.News.PageNumber.ToString())'
				},
					function (result) {
					    $("#news-list").html(result);
					});
    }

    function Delete(id) {
        $.ajax({
            url: "@Url.Action("Delete")",
            cache: false,
            data: {
                id: id
            },
            success: function (result) {
                GetList();
            }
        });
    }

</script>

